<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加公告</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<!--    <script type="text/javascript" src="js/jquery.form.min.js"></script>-->

</head>
<body>
<form class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">活动内容</label>
        <div class="layui-input-block">
            <input type="text" id = "content" name="content" lay-verify="content" autocomplete="off" placeholder="请输入"
                   class="layui-input"/>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">活动标题</label>
            <div class="layui-input-block">
                <input type="text" id = "title" name="title" lay-verify="title" lay-reqtext="标题不可以为空？" placeholder="请输入"
                       autocomplete="off" class="layui-input"/>
            </div>
        </div>
    </div>
    <label class="layui-form-label">日期选择</label>
    <div class="layui-input-block">
        <input type="date" name="date" id="date1" autocomplete="off" class="layui-input">
    </div>

    <label class="layui-form-label">活动内容</label>
    <div class="layui-input-block">
        <input type="text" id = "uid" name="uid" lay-verify="uid" autocomplete="off" placeholder="请输入1,3,5"
               class="layui-input"/>
    </div>

</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>
<script src="layui/layui.all.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
        	var json={
        		'content ' :$('#content').val(),
        		'title ' :$('#title').val(),
        		'date ' :$('#date1').val(),
			}


            $.ajax({
                type: "get",
                url: "notice/add.do",
                data:$('form').serialize(),
                dataType: "json",
                success: function (data) {
                    //data就是后端返回的数据 {"code":1, "info":null}
                    if (data.code === 0) {
                        alert("添加成功！");
                        window.location.href = "notice.html"
                    } else {
                        layer.alert("添加失败");
                    }
                }
            })
        })
    });
</script>

</body>
</html>